﻿using System;
namespace FbHelperWP7NonUi.Settings
{
    public sealed class TextStyleSettings
    {
        internal delegate void StylesChanged();
        internal event StylesChanged StylesChangedEvent;

        private StyleSettings simpleTextStyle = new StyleSettings()
        {
            FontSize = 23,
            IsItalic = false,
            IsBold = false
        };

        private StyleSettings heading1Style = new StyleSettings();
        private StyleSettings heading2Style = new StyleSettings();
        private StyleSettings heading3Style = new StyleSettings();

        public TextStyleSettings()
        {
            simpleTextStyle.StyleChangedEvent += ChildStyleChangedEvent;

            heading1Style.StyleChangedEvent += ChildStyleChangedEvent;
            heading2Style.StyleChangedEvent += ChildStyleChangedEvent;
            heading3Style.StyleChangedEvent += ChildStyleChangedEvent;
        }

        public StyleSettings SimpleTextStyle
        {
            get
            {
                return simpleTextStyle;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException( "value" );

                simpleTextStyle.StyleChangedEvent -= ChildStyleChangedEvent;

                simpleTextStyle = value;

                value.StyleChangedEvent += ChildStyleChangedEvent;

                if (StylesChangedEvent != null)
                    StylesChangedEvent();
            }
        }

        public StyleSettings Heading1Style
        {
            get
            {
                return heading1Style;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException( "value" );

                heading1Style.StyleChangedEvent -= ChildStyleChangedEvent;

                heading1Style = value;

                value.StyleChangedEvent += ChildStyleChangedEvent;

                if (StylesChangedEvent != null)
                    StylesChangedEvent();
            }
        }

        public StyleSettings Heading2Style
        {
            get
            {
                return heading2Style;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException( "value" );

                heading2Style.StyleChangedEvent -= ChildStyleChangedEvent;

                heading2Style = value;

                value.StyleChangedEvent += ChildStyleChangedEvent;

                if (StylesChangedEvent != null)
                    StylesChangedEvent();
            }
        }

        public StyleSettings Heading3Style
        {
            get
            {
                return heading3Style;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException( "value" );

                heading3Style.StyleChangedEvent -= ChildStyleChangedEvent;

                heading3Style = value;

                value.StyleChangedEvent += ChildStyleChangedEvent;

                if (StylesChangedEvent != null)
                    StylesChangedEvent();
            }
        }

        void ChildStyleChangedEvent()
        {
            if (StylesChangedEvent != null)
                StylesChangedEvent();
        }
    }
}
